package com.yanqu.road.server.gameplayer.module.activity.cat;

import com.yanqu.road.dao.impl.activity.cat.CatConfigDaoImpl;
import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.cat.Position;
import com.yanqu.road.entity.activity.cat.config.CatLottery;
import com.yanqu.road.entity.activity.cat.config.CatMissionInfo;
import com.yanqu.road.entity.activity.cat.config.CatNpcInfo;
import com.yanqu.road.entity.activity.cat.config.CatSword;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class CatActivityConfig {

    /**
     * 列数
     */
    public static final int COLUMN_NUM = 7;

    /**
     * 行数
     */
    public static final int ROW_NUM = 7;

    /**
     * 主角初始位置（X坐标）
     */
    public static final int ROLE_INIT_X = 3;

    /**
     * 主角初始位置（Y坐标）
     */
    public static final int ROLE_INIT_Y = 0;

    ActivityInfo activityInfo;

    List<CatMissionInfo> missionInfoList;

    List<CatNpcInfo> npcInfoList;

    List<CatLottery> lotteryList;

    List<CatSword> swordList;


    //积分道具ID--怪化猫积分
    int SCORE_ITEM_ID;
    //体力包道具ID--寿司
    int ENERGY_ITEM_ID;
    //抽服装道具ID--天平
    int SKIN_EXTRACT_ITEM_ID;
    //升级武学道具ID--神秘符咒
    int KUNGFU_UPGRADE_ITEM_ID;
    //体力CD时间（s）
    int ENERGY_CD;
    //体力CD恢复值
    int ENERGY_CD_NUM;
    //体力上限值
    int ENERGY_LIMIT;
    //体力初始值
    int ENERGY_INIT;
    //怪物buff属性（形:血量+1;击杀后额外造成15%boss伤害|真|理
    String MONSTER_BUFF_PARAMETER;
    //怪物buff权重（形|真|理
    String MONSTER_BUFF_WEIGHTS;
    //玩家初始血量
    int PLAYER_HP_INIT;
    //玩家直伤技能所需怒气值
    int PLAYER_SKILL_NEED_ANGER;
    //玩家基础怒气值
    //int PLAYER_BASE_ANGER;
    //玩家连消系数(连消数（≥）;连消系数)
    String PLAYER_BATTER_PARAMETER;
    //抽奖日志显示上限
    int LOTTERY_LOG_LIMIT;
    //招募门客ID
    int PATRONS_ID;
    //服装ID
    String SKINS_ID;

    List<Integer> magnumWeights = new ArrayList<>();

    String MAGNUM_CONDITION_BATTER_NUMBER;

    //引导-怒气值
    int CAT_GUIDE_INIT_ANGER;
    //引导-达摩与小怪(新手引导初始排面(坐标，怪物id#怪物血量|坐标，达摩id))
    String CAT_GUIDE_INIT_TERRAIN;

    Position CAT_GUIDE_ANGER_POSITION;

    //直伤技能伤害加成
    int CAT_PLAYER_SKILL_ATK_PARAMETER;

    //百连vip限制
    int CAT_HUNDRED_EXTRACT_LIMIT = 8;

    //玩家直伤技能怒气上限值
    int CAT_PLAYER_SKILL_MAX_ANGER = 2000;

    int CAT_GUIDE_BOSS_POWER = 300;

    List<String> drawConsumeList;

    //缓存

    //随机形、真、理
    List<Integer> buffWeightList;
    List<String> buffList;

    //普通最后一关
    int normalLastPassId;
    //心魔第一关
    int xinMoPassId;

    public CatMissionInfo getCatMissionInfoById(int id){
        for (CatMissionInfo catMissionInfo : missionInfoList) {
            if(catMissionInfo.getId() == id){
                return catMissionInfo;
            }
        }
        return null;
    }

    public CatNpcInfo getCatNpcInfoById(int id){
        for (CatNpcInfo npcInfo : npcInfoList) {
            if(npcInfo.getId() == id){
                return npcInfo;
            }
        }
        return null;
    }

    public CatSword getCatSwordByLevel(int lv){
        for (CatSword sword : swordList) {
            if(sword.getLevel() == lv){
                return sword;
            }
        }
        return null;
    }

    /**
     * 怒气累加
     */
    public int getBattleAddition(int battleCount){
        int addition = 0;
        List<String> list = StringUtils.stringToStringList(this.PLAYER_BATTER_PARAMETER, "\\|");
        for (String str : list) {
            List<Integer> additionList = StringUtils.stringToIntegerList(str, ";");
            if(battleCount >= additionList.get(0)){
                addition += additionList.get(1);
            }
        }
        return addition;
    }



    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public void setActivityInfo(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    public List<CatMissionInfo> getMissionInfoList() {
        return missionInfoList;
    }

    public void setMissionInfoList(List<CatMissionInfo> missionInfoList) {
        this.missionInfoList = missionInfoList;
    }

    public List<CatNpcInfo> getNpcInfoList() {
        return npcInfoList;
    }

    public void setNpcInfoList(List<CatNpcInfo> npcInfoList) {
        this.npcInfoList = npcInfoList;
    }

    public List<CatLottery> getLotteryList() {
        return lotteryList;
    }

    public void setLotteryList(List<CatLottery> lotteryList) {
        this.lotteryList = lotteryList;
    }

    public List<CatSword> getSwordList() {
        return swordList;
    }

    public void setSwordList(List<CatSword> swordList) {
        this.swordList = swordList;
    }

    public boolean init() {

        CatConfigDaoImpl catConfigDao = new CatConfigDaoImpl();

        missionInfoList = catConfigDao.getCatMissionInfoList(activityInfo.getActivityId());
        npcInfoList = catConfigDao.getCatNpcInfoList(activityInfo.getActivityId());
        lotteryList = catConfigDao.getCatLotteryList(activityInfo.getActivityId());
        swordList = catConfigDao.getCatSwordList(activityInfo.getActivityId());

        for (CatMissionInfo missionInfo : missionInfoList) {
            if(missionInfo.getType() == 1){
                setNormalLastPassId(missionInfo.getId());
            }
            if(missionInfo.getType() == 3 && getXinMoPassId() == 0){
                setXinMoPassId(missionInfo.getId());
            }
        }

        Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(activityInfo.getActivityId());
        if(activityConfigMap != null){
            SCORE_ITEM_ID = activityConfigMap.get(eActivityConfigType.CAT_SCORE_ITEM_ID.getName()).getIntValue();
            ENERGY_ITEM_ID = activityConfigMap.get(eActivityConfigType.CAT_ENERGY_ITEM_ID.getName()).getIntValue();
            SKIN_EXTRACT_ITEM_ID = activityConfigMap.get(eActivityConfigType.CAT_SKIN_EXTRACT_ITEM_ID.getName()).getIntValue();
            KUNGFU_UPGRADE_ITEM_ID = activityConfigMap.get(eActivityConfigType.CAT_KUNGFU_UPGRADE_ITEM_ID.getName()).getIntValue();
            ENERGY_CD = activityConfigMap.get(eActivityConfigType.CAT_ENERGY_CD.getName()).getIntValue();
            ENERGY_CD_NUM = activityConfigMap.get(eActivityConfigType.CAT_ENERGY_CD_NUM.getName()).getIntValue();
            ENERGY_LIMIT = activityConfigMap.get(eActivityConfigType.CAT_ENERGY_LIMIT.getName()).getIntValue();
            ENERGY_INIT = activityConfigMap.get(eActivityConfigType.CAT_ENERGY_INIT.getName()).getIntValue();
            MONSTER_BUFF_PARAMETER = activityConfigMap.get(eActivityConfigType.CAT_MONSTER_BUFF_PARAMETER.getName()).getValue();
            MONSTER_BUFF_WEIGHTS = activityConfigMap.get(eActivityConfigType.CAT_MONSTER_BUFF_WEIGHTS.getName()).getValue();
            PLAYER_HP_INIT = activityConfigMap.get(eActivityConfigType.CAT_PLAYER_HP_INIT.getName()).getIntValue();
            PLAYER_SKILL_NEED_ANGER = activityConfigMap.get(eActivityConfigType.CAT_PLAYER_SKILL_NEED_ANGER.getName()).getIntValue();
            //PLAYER_BASE_ANGER = activityConfigMap.get(eActivityConfigType.CAT_PLAYER_BASE_ANGER.getName()).getIntValue();
            PLAYER_BATTER_PARAMETER = activityConfigMap.get(eActivityConfigType.CAT_PLAYER_BATTER_PARAMETER.getName()).getValue();
            LOTTERY_LOG_LIMIT = activityConfigMap.get(eActivityConfigType.CAT_LOTTERY_LOG_LIMIT.getName()).getIntValue();
            PATRONS_ID = activityConfigMap.get(eActivityConfigType.CAT_PATRONS_ID.getName()).getIntValue();
            SCORE_ITEM_ID = activityConfigMap.get(eActivityConfigType.CAT_SCORE_ITEM_ID.getName()).getIntValue();
            SKINS_ID = activityConfigMap.get(eActivityConfigType.CAT_SKINS_ID.getName()).getValue();

            MAGNUM_CONDITION_BATTER_NUMBER = activityConfigMap.get(eActivityConfigType.CAT_MAGNUM_CONDITION_BATTER_NUMBER.getName()).getValue();

            buffWeightList = StringUtils.stringToIntegerList(MONSTER_BUFF_WEIGHTS, "\\|");
            buffList = StringUtils.stringToStringList(MONSTER_BUFF_PARAMETER, "\\|");
            if(activityConfigMap.containsKey(eActivityConfigType.CAT_MAGNUM_WEIGHTS.getName())) {
                magnumWeights = StringUtils.stringToIntegerList(activityConfigMap.get(eActivityConfigType.CAT_MAGNUM_WEIGHTS.getName()).getValue(), "\\|");
            }

            CAT_GUIDE_INIT_ANGER = activityConfigMap.get(eActivityConfigType.CAT_GUIDE_INIT_ANGER.getName()).getIntValue();
            CAT_GUIDE_INIT_TERRAIN = activityConfigMap.get(eActivityConfigType.CAT_GUIDE_INIT_TERRAIN.getName()).getValue();

            if(activityConfigMap.containsKey(eActivityConfigType.CAT_GUIDE_ANGER_POSITION.getName())){
                List<Integer> list = StringUtils.stringToIntegerList(activityConfigMap.get(eActivityConfigType.CAT_GUIDE_ANGER_POSITION.getName()).getValue(), ",");
                CAT_GUIDE_ANGER_POSITION = new Position(list.get(0), list.get(1));
            }

            if(activityConfigMap.containsKey(eActivityConfigType.CAT_HUNDRED_EXTRACT_LIMIT.getName())) {
                CAT_HUNDRED_EXTRACT_LIMIT = activityConfigMap.get(eActivityConfigType.CAT_HUNDRED_EXTRACT_LIMIT.getName()).getIntValue();
            }

            if(activityConfigMap.containsKey(eActivityConfigType.CAT_PLAYER_SKILL_MAX_ANGER.getName())) {
                CAT_PLAYER_SKILL_MAX_ANGER = activityConfigMap.get(eActivityConfigType.CAT_PLAYER_SKILL_MAX_ANGER.getName()).getIntValue();
            }

            if(activityConfigMap.containsKey(eActivityConfigType.CAT_GUIDE_BOSS_POWER.getName())) {
                CAT_GUIDE_BOSS_POWER = activityConfigMap.get(eActivityConfigType.CAT_GUIDE_BOSS_POWER.getName()).getIntValue();
            }

            CAT_PLAYER_SKILL_ATK_PARAMETER = activityConfigMap.get(eActivityConfigType.CAT_PLAYER_SKILL_ATK_PARAMETER.getName()).getIntValue();

            if(activityConfigMap.containsKey(eActivityConfigType.CAT_EXTRACT_COST.getName())) {
                drawConsumeList = StringUtils.stringToStringList(activityConfigMap.get(eActivityConfigType.CAT_EXTRACT_COST.getName()).getValue(), "\\|");
            }
        }

        return true;
    }

    public int getSCORE_ITEM_ID() {
        return SCORE_ITEM_ID;
    }

    public void setSCORE_ITEM_ID(int SCORE_ITEM_ID) {
        this.SCORE_ITEM_ID = SCORE_ITEM_ID;
    }

    public int getENERGY_ITEM_ID() {
        return ENERGY_ITEM_ID;
    }

    public void setENERGY_ITEM_ID(int ENERGY_ITEM_ID) {
        this.ENERGY_ITEM_ID = ENERGY_ITEM_ID;
    }

    public int getSKIN_EXTRACT_ITEM_ID() {
        return SKIN_EXTRACT_ITEM_ID;
    }

    public void setSKIN_EXTRACT_ITEM_ID(int SKIN_EXTRACT_ITEM_ID) {
        this.SKIN_EXTRACT_ITEM_ID = SKIN_EXTRACT_ITEM_ID;
    }

    public int getKUNGFU_UPGRADE_ITEM_ID() {
        return KUNGFU_UPGRADE_ITEM_ID;
    }

    public void setKUNGFU_UPGRADE_ITEM_ID(int KUNGFU_UPGRADE_ITEM_ID) {
        this.KUNGFU_UPGRADE_ITEM_ID = KUNGFU_UPGRADE_ITEM_ID;
    }

    public int getENERGY_CD() {
        return ENERGY_CD;
    }

    public void setENERGY_CD(int ENERGY_CD) {
        this.ENERGY_CD = ENERGY_CD;
    }

    public int getENERGY_CD_NUM() {
        return ENERGY_CD_NUM;
    }

    public void setENERGY_CD_NUM(int ENERGY_CD_NUM) {
        this.ENERGY_CD_NUM = ENERGY_CD_NUM;
    }

    public int getENERGY_LIMIT() {
        return ENERGY_LIMIT;
    }

    public void setENERGY_LIMIT(int ENERGY_LIMIT) {
        this.ENERGY_LIMIT = ENERGY_LIMIT;
    }

    public int getENERGY_INIT() {
        return ENERGY_INIT;
    }

    public void setENERGY_INIT(int ENERGY_INIT) {
        this.ENERGY_INIT = ENERGY_INIT;
    }

    public String getMONSTER_BUFF_PARAMETER() {
        return MONSTER_BUFF_PARAMETER;
    }

    public void setMONSTER_BUFF_PARAMETER(String MONSTER_BUFF_PARAMETER) {
        this.MONSTER_BUFF_PARAMETER = MONSTER_BUFF_PARAMETER;
    }

    public String getMONSTER_BUFF_WEIGHTS() {
        return MONSTER_BUFF_WEIGHTS;
    }

    public void setMONSTER_BUFF_WEIGHTS(String MONSTER_BUFF_WEIGHTS) {
        this.MONSTER_BUFF_WEIGHTS = MONSTER_BUFF_WEIGHTS;
    }

    public int getPLAYER_HP_INIT() {
        return PLAYER_HP_INIT;
    }

    public void setPLAYER_HP_INIT(int PLAYER_HP_INIT) {
        this.PLAYER_HP_INIT = PLAYER_HP_INIT;
    }

    public int getPLAYER_SKILL_NEED_ANGER() {
        return PLAYER_SKILL_NEED_ANGER;
    }

    public void setPLAYER_SKILL_NEED_ANGER(int PLAYER_SKILL_NEED_ANGER) {
        this.PLAYER_SKILL_NEED_ANGER = PLAYER_SKILL_NEED_ANGER;
    }

    public String getPLAYER_BATTER_PARAMETER() {
        return PLAYER_BATTER_PARAMETER;
    }

    public void setPLAYER_BATTER_PARAMETER(String PLAYER_BATTER_PARAMETER) {
        this.PLAYER_BATTER_PARAMETER = PLAYER_BATTER_PARAMETER;
    }

    public int getLOTTERY_LOG_LIMIT() {
        return LOTTERY_LOG_LIMIT;
    }

    public void setLOTTERY_LOG_LIMIT(int LOTTERY_LOG_LIMIT) {
        this.LOTTERY_LOG_LIMIT = LOTTERY_LOG_LIMIT;
    }

    public int getPATRONS_ID() {
        return PATRONS_ID;
    }

    public void setPATRONS_ID(int PATRONS_ID) {
        this.PATRONS_ID = PATRONS_ID;
    }

    public String getSKINS_ID() {
        return SKINS_ID;
    }

    public void setSKINS_ID(String SKINS_ID) {
        this.SKINS_ID = SKINS_ID;
    }


    public List<Integer> getBuffWeightList() {
        return buffWeightList;
    }

    public List<String> getBuffList() {
        return buffList;
    }

    public List<Integer> getMagnumWeights() {
        return magnumWeights;
    }

    public String getMAGNUM_CONDITION_BATTER_NUMBER() {
        return MAGNUM_CONDITION_BATTER_NUMBER;
    }

    public int getMagnum(int attackPoint) {
        int num = 0;
        List<String> list = StringUtils.stringToStringList(MAGNUM_CONDITION_BATTER_NUMBER, "\\|");
        for (String s : list) {
            List<Integer> rangeList = StringUtils.stringToIntegerList(s, ";");
            if(attackPoint >= rangeList.get(0)){
                num = rangeList.get(1);
            }
        }
        return num;
    }

    public int getCAT_GUIDE_INIT_ANGER() {
        return CAT_GUIDE_INIT_ANGER;
    }

    public String getCAT_GUIDE_INIT_TERRAIN() {
        return CAT_GUIDE_INIT_TERRAIN;
    }

    public Position getCAT_GUIDE_ANGER_POSITION() {
        return CAT_GUIDE_ANGER_POSITION;
    }

    public int getCAT_PLAYER_SKILL_ATK_PARAMETER() {
        return CAT_PLAYER_SKILL_ATK_PARAMETER;
    }

    public int getCAT_HUNDRED_EXTRACT_LIMIT() {
        return CAT_HUNDRED_EXTRACT_LIMIT;
    }

    public int getCAT_PLAYER_SKILL_MAX_ANGER() {
        return CAT_PLAYER_SKILL_MAX_ANGER;
    }

    public int getCAT_GUIDE_BOSS_POWER() {
        return CAT_GUIDE_BOSS_POWER;
    }

    public List<String> getDrawConsumeList() {
        return drawConsumeList;
    }

    public int getNormalLastPassId() {
        return normalLastPassId;
    }

    public void setNormalLastPassId(int normalLastPassId) {
        this.normalLastPassId = normalLastPassId;
    }

    public int getXinMoPassId() {
        return xinMoPassId;
    }

    public void setXinMoPassId(int xinMoPassId) {
        this.xinMoPassId = xinMoPassId;
    }
}
